package com.logistics.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.easybuild.core.hibernate.StringPojoHibernateHandler;

import com.logistics.Pickup;
import com.logistics.PickupQueryParam;

@Repository
public class PickupDaoImpl extends StringPojoHibernateHandler<Pickup> implements PickupDao {

	@Override
	public List<Pickup> query(PickupQueryParam param) {
		return queryWithParameter(param, "p", "p.createDate desc", new QueryCriteriaSetter() {

			@Override
			public void setCriteria(StringBuffer hql, Map<String, Object> values) {
				
			}
		});
	}

	@Override
	protected Class<Pickup> getEntityClass() {
		return Pickup.class;
	}

	@Override
	public List<Pickup> needRemind() {
		StringBuffer hql = new StringBuffer();
		hql.append("from ");
		hql.append(Pickup.class.getName());
		hql.append(" where remind = ? order by createDate desc");
		
		return query(hql.toString(), true);
	}

	@Override
	public void updatePrintStatus(List<Pickup> pickups) {
		batchedUpdating(pickups, 30);
	}

	@Override
	public void updatePickupStatus(String id) {
		StringBuffer hql = new StringBuffer("update ");
		hql.append(Pickup.class.getName());
		hql.append(" set status = 1");
		hql.append(" where id = ?");
		bulkUpdate(hql.toString(), id);
	}

	@Override
	public List<Pickup> needPrint() {
		StringBuffer hql = new StringBuffer();
		hql.append("from ");
		hql.append(Pickup.class.getName());
		hql.append(" where print = ? order by createDate desc");
		
		return query(hql.toString(), true);
	}

}
